WITHDRAW_CONFIG = {
    'real_time_report': False,
    'group_by': '_chn.keyword',
    'interval_type_list': ['day', 'hour'],
    'target_event_id': ['withdraw', 'withdraw_apply', 'withdraw_financial', 'withdraw_personal_check',
                        'withdraw_return', 'withdraw_risk_check'],
    'values': [
        {
            "value_id": "apply_user",
            "target_value": "_user_id",
            "value_name": "发起人数",
            "filter": [
                {'term': {'_event_id': 'withdraw_apply'}},
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "发起提现订单的人数"
        },
        {
            "value_id": "apply_count",
            "target_value": "_user_id",
            "value_name": "发起次数",
            "filter": [
                {'term': {'_event_id': 'withdraw_apply'}},
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "发起提现订单的次数"
        },
        {
            "value_id": "apply_amount",
            "target_value": "withdraw_apply_price",
            "value_name": "发起金额",
            "filter": [
                {'term': {'_event_id': 'withdraw_apply'}},
            ],
            "value_type": "float",
            "adjust_amount": True,
            "description": "发起订单的总金额"
        },
        {
            "value_id": "risk_user",
            "target_value": "_user_id",
            "value_name": "风控人数",
            "filter": [
                {'term': {'_event_id': 'withdraw_risk_check'}},
                {'term': {'withdraw_risk_check_result': 'rejection'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "被系统审核拦截的人数"
        },
        {
            "value_id": "risk_count",
            "target_value": "_user_id",
            "value_name": "风控次数",
            "filter": [
                {'term': {'_event_id': 'withdraw_risk_check'}},
                {'term': {'withdraw_risk_check_result': 'rejection'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "被系统审核拦截的订单数量"
        },
        {
            "value_id": "risk_amount",
            "target_value": "withdraw_risk_check_price",
            "value_name": "风控金额",
            "filter": [
                {'term': {'_event_id': 'withdraw_risk_check'}},
                {'term': {'withdraw_risk_check_result': 'rejection'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
            "description": "被系统拦截的订单总金额"
        },
        {
            "value_id": "personal_check_count",
            "target_value": "_user_id",
            "value_name": "审核次数",
            "filter": [
                {'term': {'_event_id': 'withdraw_personal_check'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "被系统拦截的订单人工审核完成（通过/拒绝）的次数"
        },
        {
            "value_id": "personal_check_interval",
            "target_value": "withdraw_personal_check_check_interval",
            "value_name": "审核时长",
            "filter": [
                {"term": {"_event_id": "withdraw_personal_check"}}
            ],
            "operation": "avg",
            "value_type": "long",
            "description": "指定条件下被系统拦截的订单人工审核完成（通过/拒绝）的平均时长"
        },
        {
            "value_id": "timeout_personal_check",
            "target_value": "_user_id",
            "value_name": "超时次数",
            "filter": [
                {"term": {"_event_id": "withdraw_personal_check"}},
                {"range": {"withdraw_personal_check_check_interval": {"gte": 60 * 10}}},
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "指定条件下被系统拦截的订单人工审核完成（通过/拒绝）的平均时长"
        },
        {
            "value_id": "personal_intercept_user",
            "target_value": "_user_id",
            "value_name": "拒绝人数",
            "filter": [
                {'term': {'_event_id': 'withdraw_personal_check'}},
                {'term': {'withdraw_personal_check_result': 'rejection'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "订单被人工拒绝的人数"
        },
        {
            "value_id": "personal_intercept_count",
            "target_value": "_user_id",
            "value_name": "拒绝次数",
            "filter": [
                {'term': {'_event_id': 'withdraw_personal_check'}},
                {'term': {'withdraw_personal_check_result': 'rejection'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "订单被人工拒绝的次数"
        },
        {
            "value_id": "personal_intercept_amount",
            "target_value": "withdraw_personal_check_price",
            "value_name": "拒绝金额",
            "filter": [
                {'term': {'_event_id': 'withdraw_personal_check'}},
                {'term': {'withdraw_personal_check_result': 'rejection'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
            "description": "订单被人工拒绝的金额"
        },
        {
            "value_id": "arrived_user",
            "target_value": "_user_id",
            "value_name": "到账人数",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "订单到账的人数"
        },
        {
            "value_id": "arrived_count",
            "target_value": "_user_id",
            "value_name": "到账次数",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "订单到账的次数"
        },
        {
            "value_id": "arrived_amount",
            "target_value": "withdraw_real_price",
            "value_name": "到账金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
            "description": "订单到账的金额"
        },
        {
            "value_id": "order_amount",
            "target_value": "withdraw_price",
            "value_name": "订单金额",
            "filter": [
                {'term': {'_event_id': 'withdraw'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
            "hide_result": True
        },
        {
            "value_id": "total_tax_amount",
            "value_name": "手续费",
            "value_expr": "order_amount - arrived_amount",
            "adjust_amount": True,
            "description": "到账的订单收取的手续费=订单金额-到账金额"
        },
        {
            "value_id": "arrived_rate",
            "value_name": "到账率",
            "value_expr": "arrived_count / (apply_count - personal_intercept_count)",
            "is_percentage": True,
            "fmt": lambda v: float("%.2f" % (v * 100)),
            "description": "到账次数/（发起次数-拒绝次数）"
        },
        {
            "value_id": "third_time_interval",
            "target_value": "withdraw_third_time_interval",
            "value_name": "到账时长",
            "filter": [
                {"term": {"_event_id": "withdraw"}}
            ],
            "operation": "avg",
            "value_type": "long",
            "description": "指定条件下到账的订单从发送给第三方到到账时间的时间间隔"
        },
        {
            "value_id": "timeout_third_time",
            "target_value": "_user_id",
            "value_name": "超时次数",
            "filter": [
                {"term": {"_event_id": "withdraw"}},
                {"range": {"withdraw_third_time_interval": {"gte": 60 * 30}}},
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "到账时长超过30分钟的订单数量"
        },
        {
            "value_id": "return_user",
            "target_value": "_user_id",
            "value_name": "返款人数",
            "filter": [
                {'term': {'_event_id': 'withdraw_return'}}
            ],
            "operation": "cardinality",
            "value_type": "long",
            "description": "被拒绝后返款的人数"
        },
        {
            "value_id": "return_count",
            "target_value": "_user_id",
            "value_name": "返款次数",
            "filter": [
                {'term': {'_event_id': 'withdraw_return'}}
            ],
            "operation": "value_count",
            "value_type": "long",
            "description": "被拒绝后返款的次数"
        },
        {
            "value_id": "return_amount",
            "target_value": "withdraw_return_price",
            "value_name": "返款金额",
            "filter": [
                {'term': {'_event_id': 'withdraw_return'}}
            ],
            "value_type": "float",
            "adjust_amount": True,
            "description": "被拒绝后返款的金额"
        },
        {
            "value_id": "prohibit_amount",
            "value_name": "有效拦截金额",
            "adjust_amount": True,
            "value_expr": "apply_amount - arrived_amount - total_tax_amount - return_amount",
        },
    ]
}
